﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Matrix
{
    public class MatrixMultipilication
    {
        int[,] a;
        int[,] b;
        int[,] c;
        public void GetMatixValue()
        {
            Console.WriteLine("Enter The First Matrix Row Length :");
            int m = int.Parse(Console.ReadLine());
            Console.WriteLine("\nEnter The First Matrix Column Length :");
            int n = int.Parse(Console.ReadLine());
            a = new int[m, n];
            Console.WriteLine("\nThe Row And Column Values :");
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    Console.WriteLine("Enter Value For A Matrix :{0}{1}", i, j);
                    a[i, j] = int.Parse(Console.ReadLine());
                }
            }
            Console.WriteLine("Enter The Second Matrix Row Length :");
            m = int.Parse(Console.ReadLine());
            Console.WriteLine("\nEnter The Second Matrix Column Length :");
            n = int.Parse(Console.ReadLine());
            b = new int[m, n];
            Console.WriteLine("\nThe Row And Column Values :");
            for (int i = 0; i < b.GetLength(0); i++)
            {
                for (int j = 0; j < b.GetLength(1); j++)
                {
                    Console.WriteLine("Enter Value For A Matrix :{0}{1}", i, j);
                    b[i, j] = int.Parse(Console.ReadLine());
                }
            }
        }
        public void Trans_Matrix()
        {
            int[,] array = new int[2, 2] { { 1, 2 }, { 3, 4 } };
            for (int l = 0; l < 2; l++)
            {
                for (int o = 0; o < 2; o++)
                {
                    Console.WriteLine("{0}\t{1}{2}", array[o, l],o,l);
                    //Console.WriteLine("{0}", array[l,o]);

                }
            }
            Console.WriteLine("\n\n");
            for (int l = 0; l < 2; l++)
            {
                for (int o = 0; o < 2; o++)
                {
                    //       Console.WriteLine("{0}", array[o, l]);
                    Console.WriteLine("{0}\t{1}{2}", array[l, o],l,o);

                }
            }
            Console.ReadKey();

        }
        public void Multipilication()
        {
            if (a.GetLength(1) == b.GetLength(0))
            {
                c = new int[a.GetLength(0), b.GetLength(1)];
                for (int i = 0; i < c.GetLength(0); i++)
                {
                    for (int j = 0; j < c.GetLength(1); j++)
                    {
                        c[i, j] = 0;
                        for (int k = 0; k < a.GetLength(1); k++)
                        {

                            c[i, j] = c[i, j] + a[i, j] * b[i, j];
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine("\nEnter The Correct Dimentional Matrix Size :");
                Console.ReadKey();
            }
        }
        public void Result()
        {
            for (int i = 0; i < c.GetLength(0); i++)
            {
                for (int j = 0; j < c.GetLength(1); j++)
                {
                    Console.WriteLine("\nThe Result  : {0}{1}  :  {2}", i, j, c[i, j]);

                }

            }
            Console.ReadKey();
        }
        class Program
        {
            static void Main(string[] args)
            {
                MatrixMultipilication Call_Matrix = new MatrixMultipilication();
                Call_Matrix.GetMatixValue();
                Call_Matrix.Multipilication();
                Call_Matrix.Result();
                Call_Matrix.Trans_Matrix();
            }
        }

    }
}
